﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetNuke.Entities.Content;
using DotNetNuke.Common.Utilities;



namespace DotNetNuke.Modules.TaskManager.Components
{
    [CLSCompliant(false)]
    public class Task : ContentItem
    {
        /// <summary>
        /// Task Id identifies
        /// </summary>
        public int TaskId { get; set; }

        /// <summary>
        /// a string with the name  of the Task
        /// </summary>
        public string TaskName { get; set; }
        public string TaskDescription { get; set; }
        public int AssignedUserId { get; set; }
        public int ModuleId { get; set; }
        public DateTime TargetCompltionDate { get; set; }
        public DateTime CompletedOnDate { get; set; }
        public int CreatedByUserId { get; set; }
        public int LastModifiedByUserId { get; set; }
        public new DateTime CreatedOnDate { get; set; }
        public new DateTime LastModifiedOnDate { get; set; }
        public int PortalId { get; set; }

        public string CreatedByUser
        {
            get
            {
                return CreatedByUserId != 0 ? Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username : Null.NullString;
            }
        }
        public string LastUpdateByUser
        {
            get
            {
                return LastModifiedByUserId != 0 ? Entities.Users.UserController.GetUserById(PortalId, LastModifiedByUserId).Username : Null.NullString;
            }
        }

        #region IHydraTable Implementation
        public override void Fill(System.Data.IDataReader dr)
        {
            base.FillInternal(dr);
            TaskId = Null.SetNullInteger(dr["TaskId"]);
            TaskName = Null.SetNullString(dr["TaskName"]);
            TaskDescription = Null.SetNullString(dr["TaskDescription"]);
            AssignedUserId = Null.SetNullInteger(dr["AssignedUserId"]);
            ModuleId = Null.SetNullInteger(dr["ModuleId"]);
            TargetCompltionDate = Null.SetNullDateTime(dr["TargetCompltionDate"]);
            CompletedOnDate = Null.SetNullDateTime(dr["CompletedOnDate"]);
            CreatedByUserId = Null.SetNullInteger(dr["CreatedByUserId"]);
            LastModifiedByUserId = Null.SetNullInteger(dr["LastModifiedByUserId"]);
            CreatedOnDate = Null.SetNullDateTime(dr["CreatedOnDate"]);
            LastModifiedOnDate = Null.SetNullDateTime(dr["LastModifiedOnDate"]);



        }
        public override int KeyID
        {
            get
            {
                return TaskId;
            }
            set
            {
                TaskId = value;
            }
        }
        #endregion
    }
}